<template>
  <star-horse-dialog :visible = "batchDialogTableVisible" :title = "dialogTitle" is-batch = "true" @merge = "merge"
                     @mergeDraft = "mergeDraft"
                     @reset = "resetForm">
    <el-form :model = "ruleForm" :rules = "rules" class = "data-form" ref = "ruleForm">
      <el-table
          v-loading = "loading"
          :data = "ruleForm.batchDataList"
          fit = "true"
          border
          :row-class-name = "rowClassName"
          @selection-change = "handleDetailSelectionChange"
          ref = "tb"
      >
        <el-table-column type = "selection" fixed = "left" width = "50" align = "center"/>
        <el-table-column label = "序号" align = "center" prop = "xh" width = "80"></el-table-column>
        <el-table-column
            prop = "idDictinfoType"
            label = "主键 "
            :formatter = "dataFormat"
            min-width = "200px"
            v-if = " false "
        >
          <template #default = "scope">
            <el-form-item required :rules = "rules.idDictinfoType"
                          :prop = "'batchDataList.'+scope.$index+'.idDictinfoType'">
              <el-input clearable v-model = "scope.row.idDictinfoType"
                        placeholder = "请输入主键 "></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            prop = "dictTypeCode"
            label = "类型编码 "
            :formatter = "dataFormat"
            min-width = "200px"
            v-if = "true "
        >
          <template #default = "scope">
            <el-form-item required :rules = "rules.dictTypeCode"
                          :prop = "'batchDataList.'+scope.$index+'.dictTypeCode'">
              <el-input clearable v-model = "scope.row.dictTypeCode"
                        placeholder = "请输入类型编码 "></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            prop = "dictTypeName"
            label = "类型名称 "
            :formatter = "dataFormat"
            min-width = "200px"
            v-if = "true "
        >
          <template #default = "scope">
            <el-form-item required :rules = "rules.dictTypeName"
                          :prop = "'batchDataList.'+scope.$index+'.dictTypeName'">
              <el-input clearable v-model = "scope.row.dictTypeName"
                        placeholder = "请输入类型名称 "></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            prop = "remark"
            label = "备注 "
            :formatter = "dataFormat"
            min-width = "200px"
            v-if = "true "
        >
          <template #default = "scope">
            <el-form-item required :rules = "rules.remark" :prop = "'batchDataList.'+scope.$index+'.remark'">
              <el-input clearable v-model = "scope.row.remark"
                        placeholder = "请输入备注 "></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            prop = "createdBy"
            label = "创建人 "
            :formatter = "dataFormat"
            min-width = "200px"
            v-if = " false "
        >
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.createdBy'">
              <el-input clearable v-model = "scope.row.createdBy"
                        placeholder = "请输入创建人 "></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            prop = "updatedBy"
            label = "修改人 "
            :formatter = "dataFormat"
            min-width = "200px"
            v-if = " false "
        >
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.updatedBy'">
              <el-input clearable v-model = "scope.row.updatedBy"
                        placeholder = "请输入修改人 "></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            prop = "createdDate"
            label = "创建日期 "
            :formatter = "dataFormat"
            min-width = "200px"
            v-if = " false "
        >
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.createdDate'">
              <el-date-picker clearable v-model = "scope.row.createdDate"
                              type = "date"
                              placeholder = "请选择创建日期 ">
              </el-date-picker>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            prop = "updatedDate"
            label = "修改日期 "
            :formatter = "dataFormat"
            min-width = "200px"
            v-if = " false "
        >
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.updatedDate'">
              <el-date-picker clearable v-model = "scope.row.updatedDate"
                              type = "date"
                              placeholder = "请选择修改日期 ">
              </el-date-picker>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            prop = "version"
            label = "数据版本号 "
            :formatter = "dataFormat"
            min-width = "200px"
            v-if = " false "
        >
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.version'">
              <el-input clearable v-model = "scope.row.version"
                        placeholder = "请输入数据版本号 "></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            prop = "isDel"
            label = "是否已逻辑删除 0 否 1 是 默认 0 "
            :formatter = "dataFormat"
            min-width = "200px"
            v-if = " false "
        >
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.isDel'">
              <el-input clearable v-model = "scope.row.isDel"
                        placeholder = "请输入是否已逻辑删除 0 否 1 是 默认 0 "></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            prop = "dataNo"
            label = "数据编号 "
            :formatter = "dataFormat"
            min-width = "200px"
            v-if = " false "
        >
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.dataNo'">
              <el-input clearable v-model = "scope.row.dataNo"
                        placeholder = "请输入数据编号 "></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            prop = "local"
            label = "国际码 "
            :formatter = "dataFormat"
            min-width = "200px"
            v-if = " false "
        >
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.local'">
              <el-input clearable v-model = "scope.row.local"
                        placeholder = "请输入国际码 "></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            prop = "statusName"
            label = "状态名称 "
            :formatter = "dataFormat"
            min-width = "200px"
            v-if = " false "
        >
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.statusName'">
              <el-input clearable v-model = "scope.row.statusName"
                        placeholder = "请输入状态名称 "></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            prop = "statusCode"
            label = "状态值 "
            :formatter = "dataFormat"
            min-width = "200px"
            v-if = "true "
        >
          <template #default = "scope">
            <el-form-item required :rules = "rules.statusCode" :prop = "'batchDataList.'+scope.$index+'.statusCode'">
              <el-select clearable placeholder = "请选择状态" v-model = "scope.row.statusCode">
                <el-option
                    :key = "sitem.statusCode"
                    :label = "sitem.statusName"
                    :value = "sitem.statusCode"
                    v-for = "sitem in selectData"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column fixed = "right" label = "操作" min-width = "150px">
          <template #header = "scope">
            <span>操作</span>&nbsp;&nbsp;
            <el-button @click = "handleAddDetails(scope.row,1)" link size = "mini" type = "primary">
              <el-tooltip content = "添加一行">
                <user-icon icon = "plus" style = "vertical-align: middle;color:#409EFF;"/>
              </el-tooltip>
            </el-button>
          </template>
          <template #default = "scope">
            <el-button v-if = "scope.row.xh==ruleForm.batchDataList.length" @click = "handleAddDetails(scope.row,1)"
                       link size = "mini" type = "primary">
              <el-tooltip content = "添加一行">添加</el-tooltip>
            </el-button>
            <el-button @click = "handleAddDetails(scope.row,2)" link size = "mini" type = "danger">
              <el-tooltip content = "删除当前行">删除</el-tooltip>
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-form>
  </star-horse-dialog>
  <star-horse-dialog :visible = "dialogTableVisible" :title = "dialogTitle" @merge = "merge" @mergeDraft = "mergeDraft"
                     @reset = "resetForm">
    <el-form :model = "ruleForm" :rules = "rules" class = "data-form" ref = "ruleForm">
      <el-form-item label = "主键 " prop = "idDictinfoType" v-if = "false">
        <el-input clearable v-model = "ruleForm.idDictinfoType"
                  placeholder = "请输入主键 "></el-input>
      </el-form-item>
      <el-form-item label = "类型名称 " prop = "dictTypeName"
                    v-if = "!false" required>
        <el-input clearable v-model = "ruleForm.dictTypeName"
                  placeholder = "请输入类型名称 "></el-input>
      </el-form-item>
      <el-form-item label = "类型编码 " prop = "dictTypeCode"
                    v-if = "!false" required>
        <el-input clearable v-model = "ruleForm.dictTypeCode"
                  placeholder = "请输入类型编码 "></el-input>
      </el-form-item>

      <el-form-item label = "备注 " prop = "remark"
                    v-if = "!false">
        <el-input clearable v-model = "ruleForm.remark"
                  placeholder = "请输入备注 "></el-input>
      </el-form-item>

      <el-form-item label = "创建人 " prop = "createdBy"
                    v-if = "!true">
        <el-input clearable v-model = "ruleForm.createdBy"
                  placeholder = "请输入创建人 "></el-input>
      </el-form-item>

      <el-form-item label = "修改人 " prop = "updatedBy"
                    v-if = "!true">
        <el-input clearable v-model = "ruleForm.updatedBy"
                  placeholder = "请输入修改人 "></el-input>
      </el-form-item>

      <el-form-item label = "创建日期 " prop = "createdDate"
                    v-if = "!true">
        <el-date-picker clearable v-model = "ruleForm.createdDate" type = "date"
                        placeholder = "请选择创建日期 ">
        </el-date-picker>
      </el-form-item>

      <el-form-item label = "修改日期 " prop = "updatedDate"
                    v-if = "!true">
        <el-date-picker clearable v-model = "ruleForm.updatedDate" type = "date"
                        placeholder = "请选择修改日期 ">
        </el-date-picker>
      </el-form-item>

      <el-form-item label = "数据版本号 " prop = "version"
                    v-if = "!true">
        <el-input-number clearable v-model = "ruleForm.version"
                         placeholder = "请输入数据版本号 "/>
      </el-form-item>

      <el-form-item label = "是否已逻辑删除 0 否 1 是 默认 0 " prop = "isDel"
                    v-if = "!true">
        <el-input-number clearable v-model = "ruleForm.isDel"
                         placeholder = "请输入是否已逻辑删除 0 否 1 是 默认 0 "/>
      </el-form-item>

      <el-form-item label = "数据编号 " prop = "dataNo"
                    v-if = "!true">
        <el-input clearable v-model = "ruleForm.dataNo"
                  placeholder = "请输入数据编号 "></el-input>
      </el-form-item>

      <el-form-item label = "国际码 " prop = "local"
                    v-if = "!true">
        <el-input clearable v-model = "ruleForm.local"
                  placeholder = "请输入国际码 "></el-input>
      </el-form-item>

      <el-form-item label = "状态名称 " prop = "statusName"
                    v-if = "!true">
        <el-input clearable v-model = "ruleForm.statusName"
                  placeholder = "请输入状态名称 "></el-input>
      </el-form-item>

      <el-form-item label = "状态 " prop = "statusCode"
                    v-if = "!false">
        <el-select v-model = "ruleForm.statusCode" placeholder = "请选择状态值 ">
          <el-option
              clearable
              v-for = "sitem in selectData"
              :key = "sitem.statusCode"
              :label = "sitem.statusName"
              :value = "sitem.statusCode"
          >
          </el-option>
        </el-select>
      </el-form-item>

    </el-form>
  </star-horse-dialog>
  <star-horse-dialog :visible = "viewVisible" :title = "'查看数据'" :is-view = "true">
    <div class = "item">
      <label>类型名称 :</label>
      <div class = "content">{{ ruleForm.dictTypeName }}</div>
    </div>
    <div class = "item">
      <label>类型编码 :</label>
      <div class = "content">{{ ruleForm.dictTypeCode }}</div>
    </div>

    <div class = "item">
      <label>备注 :</label>
      <div class = "content">{{ ruleForm.remark }}</div>
    </div>
    <div class = "item">
      <label>创建人 :</label>
      <div class = "content">{{ ruleForm.createdBy }}</div>
    </div>
    <div class = "item">
      <label>修改人 :</label>
      <div class = "content">{{ ruleForm.updatedBy }}</div>
    </div>
    <div class = "item">
      <label>创建日期 :</label>
      <div class = "content">{{ createDate(ruleForm.createdDate) }}</div>
    </div>
    <div class = "item">
      <label>修改日期 :</label>
      <div class = "content">{{ createDate(ruleForm.updatedDate) }}</div>
    </div>
    <div class = "item">
      <label>数据版本号 :</label>
      <div class = "content">{{ ruleForm.version }}</div>
    </div>
    <div class = "item">
      <label>是否已逻辑删除:</label>
      <div class = "content">{{ ruleForm.isDel }}</div>
    </div>
    <div class = "item">
      <label>数据编号 :</label>
      <div class = "content">{{ ruleForm.dataNo }}</div>
    </div>
    <div class = "item">
      <label>国际码 :</label>
      <div class = "content">{{ ruleForm.local }}</div>
    </div>
    <div class = "item">
      <label>状态名称 :</label>
      <div class = "content">{{ ruleForm.statusName }}</div>
    </div>


  </star-horse-dialog>
  <el-card class = "inner_content">
    <el-form class = "search_area" size = "mini">
      <el-form-item label = "类型名称 ">
        <el-input @keydown.enter = "dataSearch" placeholder = "请输入类型名称 "
                  v-model = "searchForm.dictTypeName"/>
      </el-form-item>
      <el-form-item label = "类型编码 ">
        <el-input @keydown.enter = "dataSearch" placeholder = "请输入类型编码 "
                  v-model = "searchForm.dictTypeCode"/>
      </el-form-item>
      <el-form-item label = "状态 ">
        <el-select @keydown.enter = "dataSearch" placeholder = "请选择状态 " filterable clearable
                   v-model = "searchForm.statusCode">
          <el-option
              clearable
              v-for = "sitem in selectData"
              :key = "sitem.statusCode"
              :label = "sitem.statusName"
              :value = "sitem.statusCode"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label = "     ">
        <el-button @click = "dataSearch" link type = "primary">
          <user-icon icon = "search"/>
          <span style = "vertical-align: middle;"> 查询 </span>
        </el-button>
        <el-button @click = "dataSearch(1)" link small>
          <span style = "vertical-align: middle;"> 重置 </span>
        </el-button>
      </el-form-item>
    </el-form>
    <el-divider/>
    <star-horse-button-list
        :permission = "permission"
        :upload-url = "uploadUrl"
        @upload = "upload"
        @uploadProcess = "uploadProcess"
        @uploadError = "uploadError"
        @uploadSuccess = "uploadProcess"
        @btnOperation = "btnOperation"
    />
    <el-table
        :id = "tableDataId"
        :data = "dataList"
        @row-dblclick = "editData"
        @selection-change = "handleSelectionChange"
        :row-key = "getRowIdentity"
        stripe = "true"
        fit = "true"
        highlight-current-row = "true"
        border
        ref = "multipleTable"
    >
      <el-table-column fixed width = "1"/>
      <el-table-column
          type = "selection"
          align = "center"
          fixed = "left"
          :reserve-selection = "true"
      />
      <el-table-column
          prop = "idDictinfoType"
          label = "主键 "
          min-width = "180px"
          :formatter = "dataFormat"
          v-if = " false "
          :show-overflow-tooltip = "true">
      </el-table-column>
      <el-table-column
          prop = "dictTypeName"
          label = "类型名称 "
          min-width = "180px"
          :formatter = "dataFormat"
          v-if = " true "
          :show-overflow-tooltip = "true">
      </el-table-column>
      <el-table-column
          prop = "dictTypeCode"
          label = "类型编码 "
          min-width = "180px"
          :formatter = "dataFormat"
          v-if = " true "
          :show-overflow-tooltip = "true">
      </el-table-column>

      <el-table-column
          prop = "remark"
          label = "备注 "
          min-width = "180px"
          :formatter = "dataFormat"
          v-if = " true "
          :show-overflow-tooltip = "true">
      </el-table-column>
      <el-table-column
          prop = "createdBy"
          label = "创建人 "
          min-width = "180px"
          :formatter = "dataFormat"
          v-if = " false "
          :show-overflow-tooltip = "true">
      </el-table-column>
      <el-table-column
          prop = "updatedBy"
          label = "修改人 "
          min-width = "180px"
          :formatter = "dataFormat"
          v-if = " false "
          :show-overflow-tooltip = "true">
      </el-table-column>
      <el-table-column
          prop = "createdDate"
          label = "创建日期 "
          min-width = "180px"
          :formatter = "dataFormat"
          v-if = " false "
          :show-overflow-tooltip = "true">
      </el-table-column>
      <el-table-column
          prop = "updatedDate"
          label = "修改日期 "
          min-width = "180px"
          :formatter = "dataFormat"
          v-if = " false "
          :show-overflow-tooltip = "true">
      </el-table-column>
      <el-table-column
          prop = "version"
          label = "数据版本号 "
          min-width = "180px"
          :formatter = "dataFormat"
          v-if = " false "
          :show-overflow-tooltip = "true">
      </el-table-column>
      <el-table-column
          prop = "isDel"
          label = "是否已逻辑删除 0 否 1 是 默认 0 "
          min-width = "180px"
          :formatter = "dataFormat"
          v-if = " false "
          :show-overflow-tooltip = "true">
      </el-table-column>
      <el-table-column
          prop = "dataNo"
          label = "数据编号 "
          min-width = "180px"
          :formatter = "dataFormat"
          v-if = " false "
          :show-overflow-tooltip = "true">
      </el-table-column>
      <el-table-column
          prop = "local"
          label = "国际码 "
          min-width = "180px"
          :formatter = "dataFormat"
          v-if = " false "
          :show-overflow-tooltip = "true">
      </el-table-column>
      <el-table-column
          prop = "statusName"
          label = "状态名称 "
          min-width = "180px"
          :formatter = "dataFormat"
          v-if = " true "
          :show-overflow-tooltip = "true">
      </el-table-column>
      <el-table-column
          prop = "statusCode"
          label = "状态值 "
          min-width = "180px"
          :formatter = "dataFormat"
          v-if = " false "
          :show-overflow-tooltip = "true">
      </el-table-column>
      <el-table-column fixed = "right" label = "操作" min-width = "180px">
        <template #default = "scope">
          <el-button v-if = "permission.edit" @click = "editById(scope.row[primaryKey])" link title = ""
                     type = "primary">
            <el-tooltip content = "编辑">编辑</el-tooltip>
          </el-button>
          <el-button v-if = "permission.view" @click = "viewById(scope.row[primaryKey])" link title = ""
                     type = "primary">
            <el-tooltip content = "查看">查看</el-tooltip>
          </el-button>
          <el-button v-if = "permission.add" @click = "addDict(scope.row['dictTypeCode'])" link title = ""
                     type = "primary">
            <el-tooltip content = "添加字典">添加字典</el-tooltip>
          </el-button>
          <el-button v-if = "permission.delete" @click = "deleteById(scope.row[primaryKey])" link title = ""
                     type = "danger">
            <el-tooltip content = "删除">删除</el-tooltip>
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-divider/>
    <el-pagination
        :total = "totalData"
        @current-change = "pageChangeClick"
        @size-change = "pageSizeClick"
        layout = "total, sizes, prev, pager, next, jumper"
        v-model:currentPage = "currentPage"
        v-model:page-size = "pageSize"
        v-model:pageCount = "totalPage"/>
  </el-card>
</template>
<style lang = "scss" scoped>

</style>
<script>


import {ref} from "vue";
import {common} from "../../api/common";

export default {
  name: "DictinfoType",

  mixins: [common],
  setup() {
    return {}
  },
  data() {
    const loadByPageUrl = ref("/system-config/system/dictinfoType/pageList");
    const mergeUrl = ref("/system-config/system/dictinfoType/merge");
    const mergeDraftUrl = ref("/system-config/system/dictinfoType/mergeDraft");
    const batchMergeUrl = ref("/system-config/system/dictinfoType/mergeBatch");
    const batchMergeDraftUrl = ref("/system-config/system/dictinfoType/mergeBatchDraft");
    const loadByIdUrl = ref("/system-config/system/dictinfoType/getById");
    const deleteUrl = ref("/system-config/system/dictinfoType/batchDeleteById");
    const exportAllUrl = ref("/system-config/system/dictinfoType/exportData");
    const downloadTemplateUrl = ref("/system-config/system/dictinfoType/downloadTemplate");
    const uploadUrl = ref("/system-config/system/dictinfoType/importData");
    const userConditionUrl = ref("/system-config/system/dictinfoType/getAllByCondition");
    const primaryKey = "idDictinfoType";
    return {
      loadByPageUrl,
      mergeUrl,
      mergeDraftUrl,
      batchMergeUrl,
      batchMergeDraftUrl,
      loadByIdUrl,
      deleteUrl,
      exportAllUrl,
      downloadTemplateUrl,
      uploadUrl,
      userConditionUrl,
      tableDataId: "dictinfoType",
      primaryKey: primaryKey || "unknown",
      rules: {
        idDictinfoType: [{required: true, message: "必选项不能为空", trigger: "blur"}],
        dictTypeCode: [{required: true, message: "必选项不能为空", trigger: "blur"}],
        dictTypeName: [{required: true, message: "必选项不能为空", trigger: "blur"}],
        remark: [{required: true, message: "必选项不能为空", trigger: "blur"}],
        statusCode: [{required: true, message: "必选项不能为空", trigger: "blur"}],
      }
    }
  },
  methods: {
    addDict(typeCode) {
      this.$router.push({path: "/dict_list", query: {typeCode}});
    },
    dataFormat(row, column, cellValue, index) {
      let _this = this;
      cellValue = _this.commonDataFormat(row, column, cellValue, index);
      return _this.parseCodeToName(column.property, cellValue);
    },
    parseCodeToName(name, cellValue) {
      return cellValue;
    },
    /**
     * 初始化数据
     */
    init: function () {
      let _this = this;
      _this.dataList = [];
      _this.selectData = [];
      _this.loadByPage(_this.currentPage, _this.pageSize);
      _this.loadPermissionResources();
      _this.commonSelectData("sys_dictinfo_type");
    },

    parseSearchData: function () {
      let _this = this;
      let data = _this.searchForm;
      let arr = [];
      //生成的数据，默认所有查询字段完全匹配
      if (data.idDictinfoType) {
        arr.push({
          propertyName: "idDictinfoType",
          value: data.idDictinfoType,
          operation: "eq"
        });
      }
      if (data.dictTypeCode) {
        arr.push({
          propertyName: "dictTypeCode",
          value: data.dictTypeCode,
          operation: "lk"
        });
      }
      if (data.dictTypeName) {
        arr.push({
          propertyName: "dictTypeName",
          value: data.dictTypeName,
          operation: "lk"
        });
      }
      if (data.remark) {
        arr.push({
          propertyName: "remark",
          value: data.remark,
          operation: "eq"
        });
      }
      if (data.statusCode) {
        arr.push({
          propertyName: "statusCode",
          value: data.statusCode,
          operation: "eq"
        });
      }

      return arr;
    }
  },
  created() {
    let _this = this;
    _this.init();
  }
}
</script>